package com.palfund.mvp.home.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.palfund.mvp.R;
import com.palfund.mvp.home.contract.LoginContract;
import com.palfund.mvp.home.presenter.LoginPresenter;

public class MainActivity extends AppCompatActivity implements LoginContract.View {
    private LoginContract.Presenter mPresenter;
    private EditText mEditText_name;
    private EditText mEditText_password;
    private ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mEditText_name = (EditText) findViewById(R.id.editText_name);
        mEditText_password = (EditText) findViewById(R.id.editText_password);
        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
        new LoginPresenter(this);
    }

    public void click(View view) {
        mPresenter.login();
    }

    @Override
    public void setPresenter(LoginContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getName() {
        return mEditText_name.getText().toString();
    }

    @Override
    public String getPassword() {
        return mEditText_password.getText().toString();
    }

    @Override
    public void showProgress() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        mProgressBar.setVisibility(View.GONE);
    }

    @Override
    public void reset() {
        mEditText_name.setText("");
        mEditText_password.setText("");
    }

    @Override
    public void success() {
        Toast.makeText(this, "成功", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void failed() {
        Toast.makeText(this, "失败", Toast.LENGTH_SHORT).show();
    }
}
